package com.ruoyi.web.controller.bookkeeping;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.bookkeeping.domain.param.AddBookSortParam;
import com.ruoyi.bookkeeping.domain.param.PageQueryParam;
import com.ruoyi.bookkeeping.domain.param.UpdateBookSortParam;
import com.ruoyi.bookkeeping.domain.vo.BookSortVo;
import com.ruoyi.bookkeeping.domain.vo.MsgResult;
import com.ruoyi.bookkeeping.domain.vo.TableDataInfoVo;
import com.ruoyi.bookkeeping.util.GetPageUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.poi.ss.formula.functions.T;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.bookkeeping.service.IBookSortService;

import java.util.List;

/**
 * 分类Controller
 * 
 * @author ruoyi
 * @date 2023-02-24
 */
@RestController
@RequestMapping("/bookkeeping/sort")
@Api(tags = "分类模块")
public class BookSortController extends BaseController
{
    @Autowired
    private IBookSortService bookSortService;

    @GetMapping("/list")
    @ApiOperation("查询分类列表")
    public TableDataInfoVo<List<BookSortVo>> list(PageQueryParam pageQuery)
    {
        Page page = GetPageUtil.getPages(pageQuery.getPageNum(),pageQuery.getPageSize(),bookSortService.selectBookSortList(getUserId()));
        return getDataTable(page.getRecords(),page.getTotal());
    }

    @GetMapping(value = "/{sortId}")
    @ApiOperation("获取分类详细信息")
    public MsgResult getInfo(@PathVariable("sortId") Long sortId)
    {
        return success(bookSortService.selectBookSortBySortId(sortId,getUserId()));
    }

    @Log(title = "分类", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增分类")
    public MsgResult add(@RequestBody AddBookSortParam addBookSortParam)
    {
        return toAjax(bookSortService.insertBookSort(addBookSortParam,getUserId()));
    }

    @Log(title = "分类", businessType = BusinessType.UPDATE)
    @PutMapping
    @ApiOperation("修改分类")
    public MsgResult<T> edit(@RequestBody UpdateBookSortParam updateBookSortParam)
    {
        return toAjax(bookSortService.updateBookSort(updateBookSortParam,getUserId()));
    }

    @Log(title = "分类", businessType = BusinessType.DELETE)
	@DeleteMapping("/{sortIds}")
    @ApiOperation("删除分类")
    public MsgResult remove(@PathVariable Long[] sortIds)
    {
        return toAjax(bookSortService.deleteBookSortBySortIds(sortIds,getUserId()));
    }
}
